package com.spider.admin.service.agent;

import com.spider.admin.conf.CommandExecResult;
import com.spider.admin.conf.ENVConf;
import com.spider.admin.conf.ResultMessage;
import com.spider.admin.exception.SpiderException;
import com.spider.admin.utils.CommonUtil;
import com.spider.admin.utils.OSCommandUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

@Slf4j
@Service
public class AgentRunServiceImpl implements AgentRunService {

    @Autowired
    private ENVConf envConf;

    @Override
    public CommandExecResult startAgent() throws SpiderException {
        if (OSCommandUtil.hasRunPort(envConf.getServerPort())) {
            throw new SpiderException(ResultMessage.FAILED_PARAMS_VALIDATE.getCode(), "端口已占用");
        }
        return null;
    }

    @Override
    public CommandExecResult stopAgent() throws SpiderException {
        return null;
    }

    @Override
    public CommandExecResult reloadAgent() throws SpiderException {
        return null;
    }

    @Override
    public CommandExecResult testAgentConf() throws SpiderException {
        return null;
    }


//    public static void main(String[] args) {
////        String command = "nginx -s stop";
////        String commandPath = "D:\\spider\\spider-agent";
////        try {
//////            CommandExecResult result = executeCmdForWin(commandPath, command, true);
//////            System.out.println(result.toString());
////        } catch (Exception e) {
////            e.printStackTrace();
////        }
//        boolean bol = new AgentRunServiceImpl().hasRunPort(9091);
//        System.out.println(bol);
//    }
}


